<%@ page language="java" pageEncoding="UTF-8"%>
<%@ include file="/common/taglibs.jsp"%>
<%@ taglib prefix="probiz" tagdir="/WEB-INF/tags/probiz"%>
<%@ taglib prefix="other" tagdir="/WEB-INF/tags/other"%>
<head>
	<probiz:pageHeading pageHeadingKey="appResourceList.heading" />
	<c:if test="${not empty param.direct}">
		<c:set var="hideMainDiv" value="true" scope="request"/>
	</c:if>
</head>

<content tag="buttons">
	<probiz:iconBtn btnType="add" onclick="dlgResourceForm_show({parentId:jCategoryTree.getSelected()[0].id})" />
	<probiz:iconBtn btnType="delete" onclick="deleteResources('frontResource')" id="multiDelete"/>
</content>

<div id="contentList">
	<search:searchBox formAction="${ctxPath}/system/frontResource.html" enableMoreSearch="false" searchOnclick="searchResources('frontResource',true);return false;" formId="resourceSearchCriteria">
		<div class="basic_search">
			<table border="0" cellspacing="0" cellpadding="0" class="search_table">
				<tr>
					<th width="70px"><label for="pre_resourceName"><fmt:message key="appResource.resourceName"/>:</label></th>
					<td>
						<input type="text" id="pre_resourceName" name="resourceName" value="${param.resourceName}" style="width:150px" class="inputtxt"  />&nbsp;
					</td>
				</tr>
			</table>
		</div>
		<div class="more_search"></div>
	</search:searchBox>
	
	<div class="tree">
		<div class="tree_wrap">
			<div class="hd"></div>
				<div class="content" id="categoryTree">
					<c:set var="ui_tree" value="true" scope="request"/>
					<ul class="simpleTree">
						<li class="root" id='0'>
							<ul>
							<li id="-1" class="folder-open-last"><span>根目录</span>(${fn:length(groupList)})<ul>
								<c:forEach items="${groupList}" var="g" varStatus="varStatus">
									<li id='${g.resourceGroupId}'>
										<span>${g.groupName}</span>(${fn:length(g.appResources)})</li>
								</c:forEach>
							</ul></li></ul>
						</li>
					</ul>
				</div>
			<div class="ft"></div>
		</div>
	</div>
	<div class="tree_r">
		<div id="resourceResults" class="tree_r_wrap">
			<%--ajaxLoad file="/product/include/contentListBody.jspf" --%>
		</div>
	</div>

</div>	

<fmt:message key="button.save" var="buttonSave"/>
<fmt:message key="button.cancel" var="buttonCancel"/>
<fmt:message key="appResourceDetail.heading" var="dialogTile"/>
<probiz:ui_dialog id="ResourceForm" width="640" height="280" title="${dialogTile}" url="${ctxPath}/system/frontResource/dialog.html?doAction=add" buttons="'${buttonSave}':fnSaveResource,'${buttonCancel}':dlgResourceForm_close"/>
<script type="text/javascript">

function fnSaveResource(){
	if(!validateForm( document.getElementById("appResourceForm") )){
		alert(__vaMsg.notPass);
		return;
	}
	
	var parameters = $j("#appResourceForm").serialize();
 $j.post(__ctxPath+'/system/frontResource.html?doAction=save', parameters, fnCompleteSaveResource,"json");
}

function fnCompleteSaveResource(data){
	if(data.rtn=="success"){
		window.location.href=__ctxPath+'/system/frontResource.html?parentId='+data.rtnv;
	}else{
		var jFiledErrors=data.jFiledErrors;
		$j("#jFieldErrorDiv").hide();
		$j("#jFieldErrorDiv").html("");
		$j.each(jFiledErrors,function(index,jFieldError){
 		if(jFieldError.field){
 			var fieldInput=$j(':input[name='+jFieldError.field+']:last');
 			__handleVaErrMsg(fieldInput.get(0), jFieldError.message);
 		}
 		$j("#jFieldErrorDiv").append("<p class='cont'>"+jFieldError.message+"</p>");
 	});
 	$j("#jFieldErrorDiv").show();
	}
}

//分页
function fnOnGoToPage(){
	refreshResourceList('frontResource');
}


</script>
<%-----contentForm的div在装饰器中----%>

<%-----start:list需要加载的JS ----%>
<c:set var="ui_tree" value="true" scope="request"/>
<script type="text/javascript"	src="${ctxPath}/scripts/probiz/system/appResourceList.js?rs=${appConfig.rs}"></script>
<%-----end:  list需要加载的JS ----%>

<%-----start:form需要加载的JS ----%>
<c:set var="ui_upload" value="true" scope="request"/>
<c:set var="ui_newUpload" value="true" scope="request"/>
<c:set var="ui_QuickTip" value="true"  scope="request"/>
<c:set var="ui_datepicker" value="true"  scope="request"/>
<c:set var="ui_dialog" value="true" scope="request"/>
<c:set var="ui_tabs" value="true" scope="request"/>
<c:set var="ui_sortable_js" value="true" scope="request"/>
<script type="text/javascript">
/*******************************************
1.ajax请求之前,初始化编辑器，否则无法使用编辑器
2.ajax返回HTML后执行KE.create创建编辑器
3.id是ajax页面中的textarea，要预先设置
*******************************************/

</script>
<%-----end:  form需要加载的JS ----%>
<script type="text/javascript">
$j(document).ready(function () {
	//searchResources('frontResource',true,{'parentId':${parentId}});
	jCategoryTree = $j('#categoryTree > ul').simpleTree({
		drag:false,
		afterClick:function(node){
			clickTreeItemAction('frontResource');
		},
		afterDblClick:function(node){
		},
		afterMove:function(destination, source, pos){
		},
		afterAjax:function()
		{
		},
		animate:true
		//,docToFolderConvert:true
	})[0];
	$j("#categoryTree").show();
	$j("#${parentId} >span",$j(jCategoryTree)).attr("class","active");
	clickTreeItemAction('frontResource');
});
</script>
